package br.edu.sistemaacademico;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.ParseException;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;

import br.edu.sistemaacademico.Decorator.ConcretDecorator;
import br.edu.sistemaacademico.Memento.Memento;
import br.edu.sistemaacademico.adapter.IMenuCadastro;
import br.edu.sistemaacademico.facade.DataFacade;
import br.edu.sistemaacademico.observer.Observavel;
import br.edu.sistemaacademico.observer.Observer;
import br.edu.sistemaacademico.observer.ValidaCPF;
import br.edu.sistemaacademico.observer.ValidaCTPS;
import br.edu.sistemaacademico.observer.ValidaData;
import br.edu.sistemaacademico.observer.ValidaEspecial;
import br.edu.sistemaacademico.observer.ValidaLetras;
import br.edu.sistemaacademico.observer.ValidaNumer;
import br.edu.sistemaacademico.observer.ValidaNumerosInteiros;
import br.edu.sistemaacademico.observer.ValidaRG;
import br.edu.sistemaacademico.observer.ValidaTelefone;
import br.edu.sistemaacademico.observer.ValidaUnico;
import br.edu.sistemaacademico.pojo.Professor;
import br.edu.sistemaacademico.util.Validar;
import client.ClientCommand;

public class frmCadastroProfessor extends IMenuCadastro {

    ConcretDecorator cc = null;
    br.edu.sistemaacademico.util.ValidaData dateVal = new br.edu.sistemaacademico.util.ValidaData();
    Validar cpfVal = new Validar();
    Professor professor = new Professor();
    String causa =null;
	Memento n ;
    public frmCadastroProfessor() {
            execute();
    }

        @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        JtbRG = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jtbDtNasc = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        JtbLogin = new javax.swing.JTextField();
        jLEndereco = new javax.swing.JLabel();
        JtbSenha = new javax.swing.JPasswordField();
        jTEndereco = new javax.swing.JTextField();
        jLCidade = new javax.swing.JLabel();
        jTCPF = new javax.swing.JTextField();
        JtbSenharetry = new javax.swing.JPasswordField();
        jLTelefone = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTTelefone = new javax.swing.JTextField();
        JtbCTPS = new javax.swing.JTextField();
        infoBairro1 = new javax.swing.JLabel();
        infoBairro2 = new javax.swing.JLabel();
        infoBairro3 = new javax.swing.JLabel();
        infoBairro4 = new javax.swing.JLabel();
        jTsexo = new javax.swing.JTextField();
        infoBairro5 = new javax.swing.JLabel();
        jLBairro = new javax.swing.JLabel();
        infoBairro6 = new javax.swing.JLabel();
        infoTelefone = new javax.swing.JLabel();
        infoBairro = new javax.swing.JLabel();
        infoCidade = new javax.swing.JLabel();
        infoEndereco = new javax.swing.JLabel();
        jtbDoutorado = new javax.swing.JTextField();
        JrbContratado = new javax.swing.JRadioButton();
        jLabel11 = new javax.swing.JLabel();
        JtbDtSaida = new javax.swing.JTextField();
        JrbEfetivo = new javax.swing.JRadioButton();
        jBCancelar = new javax.swing.JButton();
        jBCadastrar = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        JcbGraducao = new javax.swing.JComboBox();
        JtbEspecializacao = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        JtbMestrado = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLNome = new javax.swing.JLabel();
        jTNome = new javax.swing.JTextField();
        infoNome = new javax.swing.JLabel();

        setPreferredSize(new java.awt.Dimension(430, 194));

        jPanel1.setPreferredSize(new java.awt.Dimension(522, 694));

        jLabel1.setText("RG");

        JtbRG.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JtbRGActionPerformed(evt);
            }
        });

        jLabel4.setText("Senha");

        jLabel2.setText("Data Nascimento");

        jLabel3.setText("Login");

        jLabel5.setText("Repita Senha");

        jLEndereco.setText("Endereco");

        JtbSenha.setText("");

        jLCidade.setText("CPF");

        JtbSenharetry.setText("");

        jLTelefone.setText("Telefone");

        jLabel6.setText("CTPS");

        jTTelefone.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTTelefoneActionPerformed(evt);
            }
        });

        infoBairro1.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoBairro1.setText("* Campo Obrigatorio");

        infoBairro2.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoBairro2.setText("* Campo Obrigatorio");

        infoBairro3.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoBairro3.setText("* Campo Obrigatorio");

        infoBairro4.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoBairro4.setText("* Campo Obrigatorio");

        jTsexo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTsexoActionPerformed(evt);
            }
        });

        infoBairro5.setFont(new java.awt.Font("Tahoma", 0, 9)); // NOI18N
        infoBairro5.setText("* Campo Obrigatorio");

        jLBairro.setText("Sexo");

        infoBairro6.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoBairro6.setText("* Campo Obrigatorio");

        infoTelefone.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoTelefone.setText(" ");

        infoBairro.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoBairro.setText("* Campo Obrigatorio");

        infoCidade.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoCidade.setText("* Campo Obrigatorio");

        infoEndereco.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoEndereco.setText("* Campo Obrigatorio");

        JrbContratado.setText("Contratado");

        jLabel11.setText("Data Saida");

        JrbEfetivo.setText("Efetivo");

        jBCancelar.setText("Cancelar");
        jBCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCancelarActionPerformed(evt);
            }
        });

        jBCadastrar.setText("Cadastrar");
        jBCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCadastrarActionPerformed(evt);
                
            }
        });

        jLabel7.setText("Graduacao");

        jLabel10.setText("Doutorado");

        JcbGraducao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        JtbEspecializacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JtbEspecializacaoActionPerformed(evt);
            }
        });

        jLabel8.setText("Especializacao");

        jLabel9.setText("Mestrado");

        jLNome.setText("Nome");

        infoNome.setFont(new java.awt.Font("Tahoma", 0, 9));
        infoNome.setText("* Campo Obrigatorio");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLEndereco)
                                    .addComponent(jLCidade)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel6)
                                    .addComponent(jLTelefone))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jTTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 312, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(infoEndereco)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 362, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(infoCidade)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 362, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jTEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 159, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addComponent(jTCPF, javax.swing.GroupLayout.DEFAULT_SIZE, 324, Short.MAX_VALUE)
                                                .addGap(38, 38, 38))
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(infoBairro)
                                                    .addComponent(JtbRG, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE)
                                                    .addComponent(JtbCTPS, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                        .addComponent(jLBairro)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTsexo, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(27, 27, 27))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(infoBairro2)
                                        .addGap(9, 9, 9))
                                    .addComponent(jTNome, javax.swing.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(infoBairro1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 362, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(infoNome)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(38, 38, 38)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(infoBairro6)
                                    .addComponent(JtbSenharetry, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(infoBairro4)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                            .addComponent(jtbDtNasc, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 265, Short.MAX_VALUE))
                                        .addComponent(infoBairro3, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(infoBairro5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)
                                        .addComponent(JtbSenha, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(JtbLogin, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGap(23, 23, 23))
                    .addComponent(jLNome)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                            .addComponent(jBCadastrar)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jBCancelar))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel7)
                                    .addGap(56, 56, 56)
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(JtbEspecializacao, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)
                                        .addComponent(JcbGraducao, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(JtbMestrado, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)
                                        .addComponent(jtbDoutorado, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel8)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 433, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel9)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 469, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel10)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 461, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(JrbContratado)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(JrbEfetivo))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel11)
                                    .addGap(57, 57, 57)
                                    .addComponent(JtbDtSaida, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 308, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGap(32, 32, 32))))
                .addGap(38, 38, 38))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(210, 210, 210)
                    .addComponent(infoTelefone)
                    .addGap(279, 279, 279)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(infoNome)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLNome)
                    .addComponent(jTNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(infoEndereco)
                        .addGap(2, 2, 2)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLEndereco)
                            .addComponent(jTEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(5, 5, 5)
                                .addComponent(infoCidade)
                                .addGap(3, 3, 3)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLCidade)
                                    .addComponent(jTCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(infoBairro)
                                .addGap(2, 2, 2)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(JtbRG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLBairro)
                                    .addComponent(jTsexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(6, 6, 6)
                        .addComponent(infoBairro1)
                        .addGap(2, 2, 2)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JtbCTPS, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGap(22, 22, 22)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLTelefone)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(144, 144, 144)
                        .addComponent(infoBairro2)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(infoBairro3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtbDtNasc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(6, 6, 6)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(infoBairro4)
                        .addGap(2, 2, 2)
                        .addComponent(JtbLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(infoBairro5)
                        .addGap(1, 1, 1)
                        .addComponent(JtbSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(7, 7, 7)
                        .addComponent(infoBairro6)
                        .addGap(1, 1, 1))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel4)
                        .addGap(18, 18, 18)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JtbSenharetry, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JcbGraducao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(JtbEspecializacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(JtbMestrado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(jtbDoutorado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JrbContratado)
                    .addComponent(JrbEfetivo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(JtbDtSaida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBCadastrar)
                    .addComponent(jBCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(66, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(160, 160, 160)
                    .addComponent(infoTelefone)
                    .addContainerGap(524, Short.MAX_VALUE)))
        );

        jScrollPane1.setViewportView(jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 551, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 475, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

        private void JtbRGActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JtbRGActionPerformed
            // TODO add your handling code here:
}//GEN-LAST:event_JtbRGActionPerformed

        private void jTTelefoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTTelefoneActionPerformed
            System.out.println("telefone");
}//GEN-LAST:event_jTTelefoneActionPerformed

        private void jTsexoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTsexoActionPerformed
            // TODO add your handling code here:
}//GEN-LAST:event_jTsexoActionPerformed

        private void jBCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCancelarActionPerformed
            cc.setVisible(false);
            return;
}//GEN-LAST:event_jBCancelarActionPerformed

        private void jBCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCadastrarActionPerformed
         operacao();
}//GEN-LAST:event_jBCadastrarActionPerformed

        private void JtbEspecializacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JtbEspecializacaoActionPerformed
            // TODO add your handling code here:
}//GEN-LAST:event_JtbEspecializacaoActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox JcbGraducao;
    private javax.swing.JRadioButton JrbContratado;
    private javax.swing.JRadioButton JrbEfetivo;
    private javax.swing.JTextField JtbCTPS;
    private javax.swing.JTextField JtbDtSaida;
    private javax.swing.JTextField JtbEspecializacao;
    private javax.swing.JTextField JtbLogin;
    private javax.swing.JTextField JtbMestrado;
    private javax.swing.JTextField JtbRG;
    private javax.swing.JPasswordField JtbSenha;
    private javax.swing.JPasswordField JtbSenharetry;
    private javax.swing.JLabel infoBairro;
    private javax.swing.JLabel infoBairro1;
    private javax.swing.JLabel infoBairro2;
    private javax.swing.JLabel infoBairro3;
    private javax.swing.JLabel infoBairro4;
    private javax.swing.JLabel infoBairro5;
    private javax.swing.JLabel infoBairro6;
    private javax.swing.JLabel infoCidade;
    private javax.swing.JLabel infoEndereco;
    private javax.swing.JLabel infoNome;
    private javax.swing.JLabel infoTelefone;
    private javax.swing.JButton jBCadastrar;
    private javax.swing.JButton jBCancelar;
    private javax.swing.JLabel jLBairro;
    private javax.swing.JLabel jLCidade;
    private javax.swing.JLabel jLEndereco;
    private javax.swing.JLabel jLNome;
    private javax.swing.JLabel jLTelefone;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTCPF;
    private javax.swing.JTextField jTEndereco;
    private javax.swing.JTextField jTNome;
    private javax.swing.JTextField jTTelefone;
    private javax.swing.JTextField jTsexo;
    private javax.swing.JTextField jtbDoutorado;
    private javax.swing.JTextField jtbDtNasc;
    // End of variables declaration//GEN-END:variables
    
    private Observavel docNome = new Observavel();
    private Observavel docEndereco = new Observavel();
    private Observavel docCPF = new Observavel();
    private Observavel docRG = new Observavel();
    private Observavel docCTPS = new Observavel();
    private Observavel docTelefone = new Observavel();
    private Observavel docLogin = new Observavel();
    private Observavel docSenha = new Observavel();
    private Observavel docRepetSenha = new Observavel();
    private Observavel docespecializacao = new Observavel();
    private Observavel docMestrado = new Observavel();
    private Observavel docDoutorado = new Observavel();
    private Observavel docData	= new Observavel();


    public void execute() {
         initComponents();
         if (cc==null)
                cc = new ConcretDecorator(this);
          initObserver();
          campoObrigatorio();
          JcbGraducao.setModel(new DefaultComboBoxModel());
          setComboBox();
          acComboBox();
          cc.setVisible(true);
    }

    public void initObserver(){
        Observer especial = new ValidaEspecial();
        Observer telefone = new ValidaTelefone();
        Observer letras = new ValidaLetras();
        Observer cpf = new ValidaCPF();
        Observer data = new ValidaData();
        Observer rg = new ValidaRG();
        Observer unico = new ValidaUnico();
        Observer numero = new ValidaCTPS();
        
          docTelefone.setDocument(jTTelefone.getDocument());
          docNome.setDocument(jTNome.getDocument());
          docRG.setDocument(JtbRG.getDocument());
          docEndereco.setDocument(jTEndereco.getDocument());
          docCPF.setDocument(jTCPF.getDocument());
          docData.setDocument(jtbDtNasc.getDocument());
          docLogin.setDocument(JtbLogin.getDocument());
          docSenha.setDocument(JtbSenha.getDocument());
          docRepetSenha.setDocument(JtbSenharetry.getDocument());
          docCTPS.setDocument(JtbCTPS.getDocument());
          docespecializacao.setDocument(JtbEspecializacao.getDocument());
          docMestrado.setDocument(JtbMestrado.getDocument());
          docDoutorado.setDocument(jtbDoutorado.getDocument());
          docData.setDocument(JtbDtSaida.getDocument());
          
          docTelefone.addObserver(telefone);
          docNome.addObserver(letras);
          docRG.addObserver(rg);
          docEndereco.addObserver(especial);
          docCPF.addObserver(cpf);
         // docData.addObserver(data);
          docLogin.addObserver(unico);
          docSenha.addObserver(unico);
          docRepetSenha.addObserver(unico);
          docCTPS.addObserver(numero);
          docespecializacao.addObserver(letras);
          docMestrado.addObserver(letras);
          docDoutorado.addObserver(letras);
          docData.addObserver(data);


          jTTelefone.getDocument().addDocumentListener(listener);
          jTNome.getDocument().addDocumentListener(listener);
          jTsexo.getDocument().addDocumentListener(listener);
          jTEndereco.getDocument().addDocumentListener(listener);
          jTCPF.getDocument().addDocumentListener(listener);
          jtbDtNasc.getDocument().addDocumentListener(listener);
          JtbLogin.getDocument().addDocumentListener(listener);
          JtbSenha.getDocument().addDocumentListener(listener);
          JtbSenharetry.getDocument().addDocumentListener(listener);
          JtbRG.getDocument().addDocumentListener(listener);
          JtbCTPS.getDocument().addDocumentListener(listener);
          JtbEspecializacao.getDocument().addDocumentListener(listener);
          JtbMestrado.getDocument().addDocumentListener(listener);
          jtbDoutorado.getDocument().addDocumentListener(listener);
          JtbDtSaida.getDocument().addDocumentListener(listener);
    }

    public void setTtelefone(Observavel observavel){
        observavel.setDocument(jTTelefone.getDocument());
        observavel.setChanged();
        observavel.notifyObservers();
        jTTelefone.setDocument(observavel.getDocument());

    }
    public void setTData(Observavel observavel){
        observavel.setDocument(JtbDtSaida.getDocument());
        observavel.setChanged();
        observavel.notifyObservers();
        JtbDtSaida.setDocument(observavel.getDocument());

    }
    
        public void setTNome(Observavel observavel){
        observavel.setDocument(jTNome.getDocument());
        observavel.setChanged();
        observavel.notifyObservers();
        jTNome.setDocument(observavel.getDocument());
    }
        
        public void setTCPF(Observavel observavel){
        observavel.setDocument(jTCPF.getDocument());
        observavel.setChanged();
        observavel.notifyObservers();
        jTCPF.setDocument(observavel.getDocument());
    }
        
        public void setTEndereco(Observavel observavel){
        observavel.setDocument(jTEndereco.getDocument());
        observavel.setChanged();
        observavel.notifyObservers();
        jTEndereco.setDocument(observavel.getDocument());
    }
        
        public void setTRG(Observavel observavel){
        observavel.setDocument(JtbRG.getDocument());
        observavel.setChanged();
        observavel.notifyObservers();
        JtbRG.setDocument(observavel.getDocument());
    }
        public void setData(Observavel observavel){
            observavel.setDocument(JtbDtSaida.getDocument());
            observavel.setChanged();
            observavel.notifyObservers();
            JtbDtSaida.setDocument(observavel.getDocument());
        }
        public void setSenha(Observavel observavel){
            observavel.setDocument(JtbSenha.getDocument());
            observavel.setChanged();
            observavel.notifyObservers();
            JtbSenha.setDocument(observavel.getDocument());
        }
        
        public void setSenhaRetry(Observavel observavel){
            observavel.setDocument(JtbSenharetry.getDocument());
            observavel.setChanged();
            observavel.notifyObservers();
            JtbSenharetry.setDocument(observavel.getDocument());
        }
        public void setLogin(Observavel observavel){
            observavel.setDocument(JtbLogin.getDocument());
            observavel.setChanged();
            observavel.notifyObservers();
            JtbLogin.setDocument(observavel.getDocument());
        }
        
        public void setCTPS(Observavel observavel){
            observavel.setDocument(JtbCTPS.getDocument());
            observavel.setChanged();
            observavel.notifyObservers();
            JtbCTPS.setDocument(observavel.getDocument());
        }

        public void setEspecializacao(Observavel observavel){
            observavel.setDocument(JtbEspecializacao.getDocument());
            observavel.setChanged();
            observavel.notifyObservers();
            JtbEspecializacao.setDocument(observavel.getDocument());

        }
        public void setMestrado(Observavel observavel){
            observavel.setDocument(JtbMestrado.getDocument());
            observavel.setChanged();
            observavel.notifyObservers();
            JtbMestrado.setDocument(observavel.getDocument());

        }
        public void setDoutorado(Observavel observavel){
            observavel.setDocument(jtbDoutorado.getDocument());
            observavel.setChanged();
            observavel.notifyObservers();
            jtbDoutorado.setDocument(observavel.getDocument());

        }
        
        public void getEventDocument(Document doc){
            if(doc.equals(docTelefone.getDocument()))
                    setTtelefone(docTelefone);
            else if(doc.equals(docNome.getDocument()))
                    setTNome(docNome);
            else if(doc.equals(docCPF.getDocument()))
                    setTCPF(docCPF);
            else if(doc.equals(docEndereco.getDocument()))
                    setTEndereco(docEndereco);
            else if(doc.equals(docRG.getDocument()))
                    setTRG(docRG);
            else if(doc.equals(docData.getDocument()))
                setData(docData);
            else if(doc.equals(docLogin.getDocument()))
                setLogin(docLogin);
            else if(doc.equals(docSenha.getDocument()))
                setSenha(docSenha);
            else if(doc.equals(docRepetSenha.getDocument()))
                setSenhaRetry(docRepetSenha);
            else if(doc.equals(docCTPS.getDocument()))
                setCTPS(docCTPS);
            else if(doc.equals(docData.getDocument()))
                setData(docData);
        }

    public void campoObrigatorio(){
        infoNome.setText("* Campo Obrigatorio");
        infoEndereco.setText("* Campo Obrigatorio");
        infoCidade.setText("* Campo Obrigatorio");
        infoBairro.setText("* Campo Obrigatorio");
        jtbDtNasc.setVisible(false);
        jLabel2.setVisible(false);
        infoBairro3.setVisible(false);
    }
    
    DocumentListener listener = new DocumentListener() {

            public void insertUpdate(DocumentEvent e) {
               getEventDocument(e.getDocument());
            }

            public void removeUpdate(DocumentEvent e) {
                getEventDocument(e.getDocument());
            }

            public void changedUpdate(DocumentEvent e) {
                 getEventDocument(e.getDocument());
            }

        };

        public void populaProfessor(Professor o){
        DataFacade facade = new DataFacade();
        o.setNome(jTNome.getText());
        o.setEndereco(jTEndereco.getText());
        o.setCpf(jTCPF.getText());
        o.setTelefone(jTTelefone.getText());
        o.setSexo(jTsexo.getText().charAt(0));
        o.setRg(JtbRG.getText());
        o.setNascimento(jtbDtNasc.getText());
        o.setLogin(JtbLogin.getText());
        if(JtbSenha.getText().equals(JtbSenharetry.getText()))
        o.setSenha(JtbSenha.getText());
        o.setCtps(JtbCTPS.getText());
        o.setGraducao(String.valueOf(JcbGraducao.getSelectedItem().toString()));
        o.setEspecializacao(JtbEspecializacao.getText());
        o.setMestrado(JtbMestrado.getText());
        o.setDoutorado(jtbDoutorado.getText());
        o.setAnoEntrada(facade.getDate());
        if(JtbDtSaida.getText().length()>9)
        facade = new DataFacade(JtbDtSaida.getText());
        if(JrbContratado.isSelected())
        o.setAnosaida(facade.getDate());
        else
        	o.setAnosaida(null);
    }
    public void populaFields(Professor o){
        jTNome.setText(o.getNome());
        jTEndereco.setText(o.getEndereco());
        jTCPF.setText(o.getCpf());
        jTTelefone.setText(o.getTelefone());
        jTsexo.setText(o.getSexo().toString());
        JtbRG.setText(o.getRg());
        jtbDtNasc.setText(o.getNascimento());
        JtbLogin.setText(o.getLogin());
        JtbSenha.setText(o.getSenha());
        JtbSenharetry.setText(o.getSenha());
        JtbCTPS.setText(o.getCtps());
        JcbGraducao.setSelectedIndex(Integer.parseInt(o.getGraducao()));
        JtbEspecializacao.setText(o.getEspecializacao());
        JtbMestrado.setText(o.getMestrado());
        jtbDoutorado.setText(o.getDoutorado());
        DataFacade facade = new DataFacade();
        facade.setDataVisao(facade.getString(o.getAnosaida()));
        JtbDtSaida.setText(facade.getString(facade.getDate()));
    }
    
    public void setComboBox(){
    	JcbGraducao.addItem("Primeiro Grau Completo");
    	JcbGraducao.addItem("Segundo Grau Completo"); 
    	JcbGraducao.addItem("Terceiro Grau Completo");
    	JcbGraducao.addItem("Primeiro Grau incompleto"); 
    }
    public void limpaFields(){
    	 jTNome.setText("");
         jTEndereco.setText("");
         jTCPF.setText("");
         jTTelefone.setText("");
         jTsexo.setText("");
         JtbRG.setText("");
         jtbDtNasc.setText("");
         JtbLogin.setText("");
         JtbSenha.setText("");
         JtbSenharetry.setText("");
         JtbCTPS.setText("");
         JcbGraducao.setSelectedIndex(1);
         JtbEspecializacao.setText("");
         JtbMestrado.setText("");
         jtbDoutorado.setText("");
         JtbDtSaida.setText("");
    }

    
	@Override
	public void menuExemplo(JMenuItem item) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void menuFechar(JMenuItem item) {
		cc.dispose();		
	}

	@Override
	public void menuLimpa(JMenuItem item) {
		limpaFields();		
	}

	@Override
	public void menuManual(JMenuItem item) {
		// TODO Auto-generated method stub		
	}

	@Override
	public void menuMementor(JMenuItem item) {
		// TODO Auto-generated method stub		
	}

	@Override
	public void menuOperacao(JMenuItem item) {
		item.setText("Cadastrar Professor");
		operacao();
	}

	@Override
	public void menuSobre(JMenuItem item) {
		
	}
	
	public void operacao(){
       if(verefica()==true){
        	populaProfessor(professor);
        	if(ClientCommand.gravar("ProfessorService",professor)==false)       	
            	JOptionPane.showMessageDialog(null, "Nao foi possivel cadastrar o professor");
            else{
            JOptionPane.showMessageDialog(null, "Professor cadastrado com sucesso");
            limpaFields();
            n = professor.save();
            }}else
            	JOptionPane.showMessageDialog(null, "Campos invalidos: "+causa);        
	}
	
	public boolean verefica(){
		if(jTNome.getText().length()<=6){		
			causa="Nome deve conter mais de 6 letras";
		return false;
		}if(jTEndereco.getText().length()<=6){	
			causa="Endereco deve conter mais de 6 letras";
			return false;
		}if(jTCPF.getText().length()<13){		
			causa="cpf invalido";
		return false;
		}if(JtbRG.getText().length()<11){
			System.out.println(JtbRG.getText().length());
			causa="rg invalido";
		return false;
	}if(JtbCTPS.getText().length()<8){		
			causa="CTPS invalido";
			return false;
	}if(jTTelefone.getText().length()<13)	{	
			causa="telefone invalido";
	}if(JrbContratado.isSelected())
	try {if(!dateVal.isDate(JtbDtSaida.getText())){	causa="data invalida"; return false;}} catch (ParseException e) {	e.printStackTrace();	}
	if(JtbLogin.getText().length()<6){		
		causa="login deve conter mais de 6 caracters";
		return false;
	}if(JtbSenha.getText().length()<8){		
		causa="senha  deve conter mais de 8 caracters";
		return false;
	}
		return true;
	}
	
	public void acComboBox(){
		JrbEfetivo.setVisible(false);
		MouseListener mouse = new MouseListener() {
			public void mouseReleased(MouseEvent e) {}
			public void mousePressed(MouseEvent e) {
				if(JrbContratado.isSelected())
					JtbDtSaida.setEnabled(false);
				else
					JtbDtSaida.setEnabled(true);					
			}
			public void mouseExited(MouseEvent e) {}
			public void mouseEntered(MouseEvent e) {			}
			public void mouseClicked(MouseEvent e) {
				
				
			}
		};
		JrbContratado.addMouseListener(mouse);
		JtbDtSaida.setEnabled(false);
	}
	
	
	public void restore(){
		professor.restore(n);
		populaFields(professor);
	}

}
